package cn.com.callback

import cn.com.elite.EliteBean
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.springframework.jdbc.core.JdbcTemplate

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import cn.com.elite.Util

/**
 *
 * @Title: apiSyncDemo
 * @Description:系统API接口开发Demo ，重点关注业务逻辑部分
 * @author: LiJuntao
 * @date 2021-07-13 23:58:55
 *
 */

public class apiSync implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(apiSync.class);

    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {

        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        long startTime = System.currentTimeMillis();

        String callBody = "";
        String getMethod = request.getMethod();
        log.debug("apiMiniPControl getMethod:" + getMethod);

        // 获取所有Header
        Map<String, String> mapHeader = new HashMap<String, String>();
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = request.getHeader(key);
            log.debug("apiMiniPControl Header-" + key + ":" + value);

            mapHeader.put(key, value);
        }

        // 获取所有参数名
        Map<String, String> mapParams = new HashMap<String, String>();
        Enumeration ep = request.getParameterNames();
        while (ep.hasMoreElements()) {
            String key = (String) ep.nextElement();
            String value = request.getParameter(key);
            log.debug("apiMiniPControl Parameter-" + key + ":" + value);
            mapParams.put(key, value);

        }
        log.debug("***原始GET请求参数:" + mapParams.toString());

        String code = "";
        String hst_guid = "";
        code = mapParams.get("code");
        hst_guid = mapParams.get("hst_guid");
        log.debug("***code:" + code + "***hst_guid:" + hst_guid);
        /*
        String sysurl = "http://47.113.26.123:8080/EliteGeneralHttpTask/GeneralService/apiSync?code="+code+"&hst_guid="+hst_guid;
        String Result = Util.doHttpGet(sysurl,"UTF-8",100000,0);
        log.debug("***Result:" + Result);
*/

        log.debug("单点登录apiSSOLoginControl校验返回:" + callBody.toString());
        return code;

    }
}